package easy;

public class Solution_1185 {

    private String[] arr = new String[]{"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"};

    public String dayOfTheWeek(int day, int month, int year) {
        int count = 0;
        for (int i = 1971; i < year; i++) {
            if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) {
                count += 366;
            } else {
                count += 365;
            }
        }
        count += dayOfYear(day, month, year);
        count %= 7;
        return arr[count];
    }

    private int[] m = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    public int dayOfYear(int day, int month, int year) {
        int count = 0;
        for (int i = 0; i < month - 1; i++) {
            count += m[i];
        }
        count += day;
        if (month > 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)) {
            count++;
        }
        return count;
    }

    public static void main(String[] args) {
        Solution_1185 model = new Solution_1185();
        System.out.println(model.dayOfTheWeek(31, 8, 2019));
        System.out.println(model.dayOfTheWeek(18, 7, 1999));
        System.out.println(model.dayOfTheWeek(15, 8, 1993));
        System.out.println(model.dayOfTheWeek(31, 12, 1971));
    }
}
